<?php

namespace app\admin\model\goods;

use app\admin\model\BaseMode;
use app\admin\validate\Goods as val_goods;
use think\exception\ValidateException;

class GoodsServer extends BaseMode
{

    protected $json=['server_id_json'];

    protected $jsonAssoc=true;

    public static function getList(){

        $where=[];
        $where['store_id']=session('store_id');
       return self::where($where)->select();

    }

    /****
     * 用户批量上传商品
     */
    public static function EditGoodsServer($data){


        unset($data['thumbs']);

        $data['store_id']=session('store_id');

        $Goods=new GoodsServer();
        $Goods->startTrans();

        try {

            if($data['id']){
                $Goods->where(['id'=>$data['id']])->update($data);
            }else{
                $Goods->save($data);
            }

            // 提交事务
            $Goods->commit();
            return array(
                'code' => 200,
                'msg' => '成功啦~!',
            );
        } catch (\Exception $e) {
            // 回滚事务
            $Goods->rollback();
            return array(
                'code' => 4006,
                'msg' => $e->getMessage(),
            );
        }

    }

}